package com.symbio.ishenapi.doctor.controller;

import com.jfinal.kit.StrKit;
import com.symbio.ishenapi.common.controller.BaseController;
import com.symbio.ishenapi.doctor.model.TmHospitalDepartment;
import io.jboot.web.controller.annotation.RequestMapping;

@RequestMapping("/TmhospitalDepartment")
public class TmHospitalDepartmentController extends BaseController {

    public void findtmhospitalDepartment(){
        TmHospitalDepartment tm = (TmHospitalDepartment) getReqBodyObject(TmHospitalDepartment.class);
        if (TmHospitalDepartment.dao.findById(tm.getId()) !=null){
            renderJsonError(40001);
            return;
        }
        if (tm.save()){
            renderJsonRet(tm);
        }else {
            renderJsonError(40002);
        }
    }


    public void findTmhospital(){ //科室主页
        TmHospitalDepartment tm = (TmHospitalDepartment) getReqBodyObject(TmHospitalDepartment.class);
        renderJsonRet(TmHospitalDepartment.dao.findTmHospitalDepartment(tm));
    }

    // TODO: 2018/11/28 此接口暂时没用到
    public void findall(){ //科室主页
//        TmDepartmentMembers tm1 = (TmDepartmentMembers) getReqBodyObject(TmDepartmentMembers.class);
//        renderJsonRet(TmDepartmentMembers.dao.findBaseTmDepartmentMembers(tm1));
    }

    //*******************************************************************************************************************
    //   2018.11.07    新增功能服务
    //*******************************************************************************************************************

    /**
     * 医生基本资料添加科室下拉列表查询
     */
    public void findDownList(){
        try {
            String hosId = getPara("hosId");
            if(StrKit.isBlank(hosId)){
                renderJsonError(50002,"医院id不能为空");
                return;
            }
            renderJsonRet(TmHospitalDepartment.dao.findDownList(hosId));
        }catch (Exception e){
            renderJsonError(50002,"科室下拉列表查询");
        }
    }

    /**
     * chen
     * 判断医院是存在科室
     * hosId 医院id
     * time:2018/11/17
     */
    public void findIsDepByHosId(){
        try {
            String hosId = getPara("hosId");
            renderJsonRet(TmHospitalDepartment.dao.findIsDepByHosId(hosId));
        }catch (Exception e){
            renderJsonError(50002,"查询失败");
        }
    }

    /** GET
     * @Author: chen
     * @Description:根据科室id查询科室的详细信息返回 科室名称，所在医院，以及科室logo
     * @Date: 15:30 2018/11/24
     * @param: [
     *              departmentId    ---科室id
     *          ]
     * @return: void
     */
    public void findDepById(){
        try {
            String departmentId = getPara("departmentId");
            TmHospitalDepartment data = TmHospitalDepartment.dao.findDepById(departmentId);
            renderJsonRet(data);
        }catch (Exception e){
            renderJsonError(50002,"科室信息查询失败");
        }
    }
}